package com.runing.service.impl;

import com.runing.config.ResponseWrapper;
import com.runing.entity.RResult;
import com.runing.entity.RRule;
import com.runing.mapper.RResultMapper;
import com.runing.mapper.RRuleMapper;
import com.runing.service.RRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lel
 * @since 2021-03-11
 */
@Service
public class RRuleServiceImpl extends ServiceImpl<RRuleMapper, RRule> implements RRuleService {

    @Autowired
    RRuleMapper ruleMapper;
    @Autowired
    RResultServiceImpl rResultService;

    public List<RRule> findAllRule(){
        List<RRule> list = ruleMapper.selectList(null);
        return list;
    }
    public ResponseWrapper updateRule(List<RRule> ruleList){
        if (ruleList.size() == 0){
            return ResponseWrapper.markCustom(false,400,"未接收到参数",null);
        }else {
            for (RRule rule : ruleList){
                ruleMapper.updateById(rule);
            }
            return ResponseWrapper.markSuccess(null);
        }
    }

    public ResponseWrapper findAllRules(){
        List<RRule> rules = findAllRule();
        List<RResult> results = rResultService.getResult();
        ResponseWrapper wrapper = ResponseWrapper.markSuccess(rules);
        wrapper.getData().put("ruleBeanList",rules);
        wrapper.getData().put("resultBeanList",results);
        return wrapper;
    }

}
